﻿#Region "Copyright"

' Copyright 2007 Ben Reichelt - http://benreichelt.net
' 
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
' 
'     http://www.apache.org/licenses/LICENSE-2.0
' 
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.


#End Region

Imports NUnit.Framework
Imports SqlPlastic
Imports System.Xml.Linq

<TestFixture()> _
Public Class MetaDataTypeTests

    Private metaData As XmlMetaData

    <SetUp()> _
    Public Sub Setup()
        metaData = ObjectMother.CreateDefaultMetaData
    End Sub

    <Test()> _
    Public Sub FindColumnTest()
        Dim type As MetaDataType = metaData.FindType(C.Type1Name)
        Dim column As MetaDataColumn = type.Column(C.Column1Name)
        Assert.IsNotNull(column)
    End Sub

    <Test()> _
    Public Sub FindAssociationTest()
        Dim type As MetaDataType = metaData.FindType(C.Type1Name)
        Dim association As MetaDataAssociation = type.Association(C.Association1Name)
        Assert.IsNotNull(association)
    End Sub

    <Test(), ExpectedException(GetType(ColumnNotFoundException))> _
    Public Sub TryFindNonExistantColumn()
        Dim type As MetaDataType = metaData.FindType(C.Type1Name)
        type.Column("INVALID-COLUMN-NAME")
    End Sub

    <Test(), ExpectedException(GetType(AssociationNotFoundException))> _
    Public Sub TryFindNonExistantAssociation()
        Dim type As MetaDataType = metaData.FindType(C.Type1Name)
        type.Association("INVALID-ASSOCIATION-NAME")
    End Sub

    <Test()> _
    Public Sub RenameTest()
        Dim type As MetaDataType = metaData.FindType(C.Type1Name)
        type.RenameTo("Ben")
        Assert.AreEqual("Ben", type.MemberName)
        type = metaData.FindType("Ben")
        Assert.AreEqual("Ben", type.MemberName)
    End Sub

End Class
